package org.hhchat.leetcode.array;

public class code665_easy {
    static class Solution {
        public boolean checkPossibility(int[] nums) {
            int n = nums.length, count = 0;

            for (int i = 0; i + 1 < n; i++) {
                if (nums[i] > nums[i + 1]) {
                    count++;
                    if (i > 0 && nums[i + 1] < nums[i - 1]) {
                        nums[i + 1] = nums[i];
                    }
                    else {
                        nums[i] = nums[i + 1];
                    }
                }
            }
            return count <= 1;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.checkPossibility(new int[]{2, 3, 3, 2, 4}));
    }
}
